
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Web
Imports System.Web.SessionState
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Imports System.IO
Imports System.Text
Imports _2bMatesSite.BO

Namespace _2bMatesSite
	''' <summary>
	''' Summary description for WebForm1.
	''' </summary>
	Public Partial Class add_special_page
		Inherits BaseWebPage

		Protected id As Integer = -1

		Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
			' this.pageTemplate.PageTitle = PageTitles.ADD_SPECIAL_PAGE;
			Dim user As User = Me.LoggedUser
			If user = Nothing Then
				Common.Utils.RedirectToLoginPage(Page)
			End If

			' init page from XML
			Me.initPageTitles(Constants.ADD_SPECIAL_PAGE, "", Form1, Nothing, Nothing)
			Me.initAdvertisements(Form1, Nothing)

			If user.Status <> Constants.appAdmin Then
				Throw New Exception(Constants.ERROR_MESSAGE_NO_ACCESS)
			End If

			If Request.Params("id") = "" Then
				Throw New Exception(Constants.ERROR_MESSAGE_MISSING_PARAMETERS)
			End If

			If Constants.SHOW_MUSIC <> Constants.SHOW_ON Then
				Throw New Exception(Constants.ERROR_MESSAGE_NO_ACCESS)
			End If

			id = Convert.ToInt32(Request.Params("id"))

			If Not Me.IsPostBack Then
				If id > 0 Then
					Dim CurrentPage As SpecialPage = SpecialPages.GetSpecialPageByID(id)
					txtName.Text = CurrentPage.Name
					txtMembersName.Text = CurrentPage.MembersName
					txtContentColumnName.Text = CurrentPage.ContentPartName
					txtContentCN1.Text = CurrentPage.ContentColumnName1
					txtContentCN2.Text = CurrentPage.ContentColumnName2
					txtContentCN3.Text = CurrentPage.ContentColumnName3
					txtRightColumnName.Text = CurrentPage.ArticlePartName
					lblTitle.Visible = False
					lblTitleEdit.Visible = True
				End If
			End If
		End Sub


		#region Web Form Designer generated code
		Protected Overloads Overrides Sub OnInit(ByVal e As EventArgs)
			'
			' CODEGEN: This call is required by the ASP.NET Web Form Designer.
			'
			InitializeComponent()
			MyBase.OnInit(e)
		End Sub

		''' <summary>
		''' Required method for Designer support - do not modify
		''' the contents of this method with the code editor.
		''' </summary>
		Private Sub InitializeComponent()
			AddHandler Me.cvNameExist.ServerValidate, AddressOf Me.cvNameExist_ServerValidate

		End Sub
#End Region

		Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs)
			If Page.IsValid Then
				Dim temp As String
				Dim tmpSpecialPage As New SpecialPage()
				tmpSpecialPage.ID = id
				temp = Request.Params(txtName.UniqueID).Trim()
				tmpSpecialPage.Name = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))
				temp = Request.Params(txtMembersName.UniqueID).Trim()
				tmpSpecialPage.MembersName = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))
				temp = Request.Params(txtContentColumnName.UniqueID).Trim()
				tmpSpecialPage.ContentPartName = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))
				temp = Request.Params(txtContentCN1.UniqueID).Trim()
				tmpSpecialPage.ContentColumnName1 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))
				temp = Request.Params(txtContentCN2.UniqueID).Trim()
				tmpSpecialPage.ContentColumnName2 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))
				temp = Request.Params(txtContentCN3.UniqueID).Trim()
				tmpSpecialPage.ContentColumnName3 = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))
				temp = Request.Params(txtRightColumnName.UniqueID).Trim()
				tmpSpecialPage.ArticlePartName = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))
				tmpSpecialPage.Save()
				Response.Redirect(Constants.SPECIAL + "?" + Constants.SPECIAL_PAGE_TYPE_ID_PARAM + "=" + tmpSpecialPage.ID)
			End If

		End Sub
		Private Sub cvNameExist_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
			Dim temp As String
			Dim nameValue As String = ""

			temp = txtName.Text.Trim()
			nameValue = temp.Substring(0, Math.Min(temp.Length, Constants.TEXT_FIELD_DEFAULT_MAX_CHARS))

			Dim spp As SpecialPage = SpecialPages.GetSpecialPageByName(nameValue)
			args.IsValid = True
			If spp <> Nothing Then
				If spp.ID <> id Then
					args.IsValid = False
				End If
			End If
		End Sub


		====================
        ' This public property was added by conversion wizard to allow the access of a protected, autogenerated member variable Form1.
		====================
        Public ReadOnly Property Form1() As System.Web.UI.HtmlControls.HtmlForm
            Get
                Return Migrated_Form1
            End Get
        End Property
        'set { Migrated_Form1 = value; }
    End Class
End Namespace






